package com.example.highclasscomponent.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.highclasscomponent.BillPagerFragment;

public class BillPagerAdapter extends FragmentPagerAdapter {

    int mYear;

    public BillPagerAdapter(@NonNull FragmentManager fm, int year) {
        super(fm,BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.mYear=year;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        BillPagerFragment view=BillPagerFragment.newInstance(getYearMonthStr(position));
        return view;
    }

    private String getYearMonthStr(int position) {
        int month=position+1;
        String monthStr=month<10?"0"+month:String.valueOf(month);
        return mYear+"-"+monthStr;

    }

    @Override
    public int getCount() {
        return 12;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return (position+1)+"月份";
    }
}
